import request from '@/utils/request';
const host = window.location.host;
import { hasIsSw,isLianxiSite, isZhongZheng} from '../utils/utils';;
export const baseurl =
  process.env.NODE_ENV === 'development' ? 'http://keanpx.shejiyuan.com/' : `/`;

export const fileurl = (is_jc: number) => {
  if (is_jc === 1) return `http://jiaocai.shejiyuan.com/`;
  return baseurl;
};

export interface getHandleParams {
  operation: string;
}
export async function getHandle(params: getHandleParams) {
  /* 记录系统日志 */
  const data = new FormData();
  const userinfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const Super = userinfo.super || 0;
  if (Super) return;
  data.append('name', localStorage.getItem('name') || '');
  data.append('operation', params.operation);
  data.append('id_number', localStorage.getItem('id_number') || '');
  data.append('ip', localStorage.getItem('ip') || '');
  return request(`${baseurl}index/index/operation`, {
    method: 'POST',
    data,
  });
}

export interface getHandleListParams {
  name: string;
  id_number: string;
  page: string;
  is_admin:string;
}
export async function getHandleList(params: getHandleListParams) {
  /* 记录系统日志 */
  const data = new FormData();
  data.append('name', params.name);
  data.append('id_number', params.id_number);
  data.append('page', params.page);
  if(isZhongZheng()){
  data.append('is_admin', params.is_admin);
  }
  return request(`${baseurl}index/index/operation_list`, {
    method: 'POST',
    data,
  });
}

export interface upSubjectMemberParams {
  name: string;
  id_number: string;
  student_type: string;
  subject: string;
  phone: string;
  type: string;
  save: string;
}
export async function upSubjectMember(params: upSubjectMemberParams) {
  /* 更新学科 */
  const data = new FormData();
  data.append('name', params.name);
  data.append('id_number', params.id_number);
  data.append('student_type', params.student_type);
  data.append('subject', params.subject);
  data.append('phone', params.phone);
  data.append('type', params.type);
  data.append('save', params.save);
  if (hasIsSw()&&!isLianxiSite()) {
    if (location.href.indexOf('tzPeoples') === -1) {
      //1是特种作业人员 2是特种设备人员
      data.append('is_sw', '2');
    } else {
      data.append('is_sw', '1');
    }
  }

  return request(`${baseurl}index/index/up_subject_member`, {
    method: 'POST',
    data,
  });
}
